package com.a16.yuejian.yuejian.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.a16.yuejian.yuejian.R;
import com.a16.yuejian.yuejian.javabean.Course;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 王子恒 on 2017/10/23.
 */

public class ClubCourseAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;

    public ClubCourseAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.club_coursecardview,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Course entity = (Course) mDataList.get(position);
        if (null == entity){
            return;
        }else {
            final ViewHolder viewHolder = (ViewHolder) holder;
            viewHolder.club_coursename.setText(entity.getCoursename());
            viewHolder.club_courseprice.setText(entity.getPrice());
            Picasso.with(mContext).load("http://10.0.2.2:8080/neu_yuejian201/public/photo/"+entity.getImg()).into(viewHolder.club_coursepic);
        }

    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView club_coursepic;
        TextView club_coursename,club_courseprice;
        LinearLayout club_coursecontainer;

        public ViewHolder(View itemView) {
            super(itemView);
            club_coursename = (TextView) itemView.findViewById(R.id.club_coursename);
            club_coursepic = (ImageView) itemView.findViewById(R.id.club_coursepic);
            club_courseprice = (TextView) itemView.findViewById(R.id.club_courseprice);
            club_coursecontainer= (LinearLayout)itemView.findViewById(R.id.club_coursecontainer);
        }
    }
}
